package week_6.practice.jsjf;

import org.junit.Test;
import week_4.practice.ArrayUnorderedList;

import java.util.Iterator;

public class LinkedBinaryTreeTest {
    BinaryTreeNode t1 = new BinaryTreeNode(20);
    BinaryTreeNode t2 = new BinaryTreeNode(17);
    BinaryTreeNode t3 = new BinaryTreeNode(23);
    BinaryTreeNode t4 = new BinaryTreeNode(28);
    BinaryTreeNode t5 = new BinaryTreeNode(12);

    LinkedBinaryTree right = new LinkedBinaryTree(t3.getElement());
    LinkedBinaryTree subleft = new LinkedBinaryTree(t4.getElement());
    LinkedBinaryTree subright = new LinkedBinaryTree(t5.getElement());

    LinkedBinaryTree left = new LinkedBinaryTree(t2.getElement(),subleft,subright);
    LinkedBinaryTree tree  = new LinkedBinaryTree(t1.getElement(),left,right);

  //  LinkedBinaryTree sublefttree = new LinkedBinaryTree(t2.getElement(),subleft,subright);
    Iterator iterator1 = tree.iteratorPreOrder();
    Iterator iterator2 = tree.iteratorPostOrder();

    @Test
    public void getRight() {
        System.out.println("树根右子树结点为："+tree.getRight().getRootElement());
        System.out.println("左子树的右子树结点为："+tree.getLeft().getRight().getRootElement());
    }

    @Test
    public void contains() {
        System.out.println("是否包含12："+tree.contains(12));
    }


    @Test
    public void preOrder() {
        System.out.println("前序遍历");
        while(iterator1.hasNext())
            System.out.print(iterator1.next()+" ");
//        ArrayUnorderedList a = new ArrayUnorderedList();
//        tree.preOrder(tree.root,a);
//        System.out.println(a.toString());
    }

    @Test
    public void postOrder() {
        System.out.println("后序遍历");
        while(iterator2.hasNext())
            System.out.print(iterator2.next()+" ");
    }

    @Test
    public void Print()
    {
        System.out.println( tree.toString());
    }
}